<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>EQEmu</title>
    <link rel="stylesheet" type="text/css" href="style/style.css"/>
    <script src="scripts/jquery.js"></script>
    <script>
    <!--
    var idx = Math.floor((Math.random()*100000000));
    function GetStatusIdx() {
        return idx++;
    }

    var offset = 0;
    function StatusTic() {
        $.getJSON("data/bug_data.html?offset="+offset+"&idx="+GetStatusIdx(),
        function(data) {
            var elm = document.getElementById("open_bugs_count");

            var cur_offset = offset / 50;
            var sep = (data.total_bug_count / 50);
            var app = "";
            for(var i = 0; i < sep; ++i) {
                var cur = 50 * i;
                var name = i + 1;
                if(i == cur_offset) {
                    app += "<b>"+name+"</b> ";
                }
                else {
                    app += "<a href='javascript:void(0)' onclick='OpenBugs(\""+cur+"\")'>"+name+"</a> ";
                }
            }
            elm.innerHTML = app;

            $("#bug_table").empty();
            var app_html = "<tr>";
            app_html += "<th scope=\"col\">Reporter</th>";
            app_html += "<th scope=\"col\">Where</th>";
            app_html += "<th scope=\"col\">Target</th>";
            app_html += "<th scope=\"col\">Descripton</th>";
            app_html += "</tr>";
            $("#bug_table").append(app_html);
            for(var i = 0; i < data.bug_count; i++) {
                app_html = "";
                var mod = i % 2;
                if(mod == 1) {
                    app_html += "<tr class=\"odd\">";
                } else {
                    app_html += "<tr>";
                }

                var bug_text = data.bugs[i].bug;
                bug_text = bug_text.replace("\r", "");
                bug_text = bug_text.replace("\n", "</br>");
                app_html += "<td>"+data.bugs[i].name+"</td>";
                app_html += "<td>"+data.bugs[i].zone+": ("+data.bugs[i].x+", "+data.bugs[i].y+", "+data.bugs[i].z+")</td>";
                app_html += "<td>"+data.bugs[i].target+"</td>";
                app_html += "<td style=\"text-align:left;\">"+bug_text+"</td>";
                app_html += "</tr>";
                $("#bug_table").append(app_html);
            }
        });
    }

    function OpenBugs(off) {
        offset = off;
        StatusTic();
    }

    $(document).ready(function() {
        setInterval("StatusTic()", 6000);
    });
    -->
    </script>
</head>
<?
    @bugs = $EQW->ListBugs(0);
    $bug_count = $EQW->CountBugs();
?>
<body>
    <div class="container">
        <?do("templates/scripts/menu_noaccess.pl");?>
        <div id="main_content" class="main">
            <div align="center"><h2>Bugs</h2></div>
            <div id="open_bugs_count" align="center">
            <?
                $cur_offset = 0;
                my $sep = ($bug_count / 50);
                for(my $i = 0; $i < $sep; ++$i) {
                    my $cur = 50 * $i;
                    my $name = $i + 1;

                    if($i == $cur_offset) {
                        print "<b>$name</b> ";
                    }
                    else {
                        print "<a href='javascript:void(0)' onclick='OpenBugs(\"$cur\")'>$name</a> ";
                    }
                }
            ?>
            </div>
            <table id="bug_table" width="100%" cellspacing="0" cellpadding="0" class="styled_table">
                <tr>
                    <th scope="col">Reporter</th>
                    <th scope="col">Where</th>
                    <th scope="col">Target</th>
                    <th scope="col">Descripton</th>
                </tr>
            <?
                $i = 0;
                for my $bugkey (@bugs) {
                    my $bug = $EQW->GetBugDetails($bugkey);
                    if(!$bug) {
                        next;
                    }

                    if($i % 2 == 1) {
                        print "<tr class=\"odd\">";
                    } else {
                        print "<tr>";
                    }

                    my $bug_val = $bug->{bug};
                    $bug_val =~ s/\r//g;
                    $bug_val =~ s/\n/<br>/g;
                    print "<td>$bug->{name}</td>";
                    print "<td>$bug->{zone}: ($bug->{x}, $bug->{y}, $bug->{z})</td>";
                    print "<td>$bug->{target}</td>";
                    print "<td style=\"text-align:left;\">$bug_val</td>";
                    print "</tr>";
                    $i++;
                }
            ?>
            </table>
        </div>
    </div>
    <div class="footer">
        &copy 2012 EQEmu. All rights reserved.
    </div>
</body>
</html>
